package com.gc.compay.service.impl;

import com.gc.compay.entity.YearVo;
import com.gc.compay.mapper.LogMapper;
import com.gc.compay.service.LogService;
import com.gsj.common.pojo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: clms-nine
 * @description: 日志Service接口实现层
 * @author: 智高超
 * @create: 2021-07-26 14:45
 **/
@Service
public class LogServiceImpl implements LogService {

    @Resource
    private LogMapper logMapper;


    @Override
    public R Log(YearVo years) {
        //拿到所有已操作的业务类型（0-其他，1-新增，2-修改，3-删除）
        List<Map> log = logMapper.Log(years);
        System.out.println(log);
        List<String> datax = new ArrayList();
        List<Integer> type = new ArrayList();

        //用来存放business_type=1的数据
        List count1 = new ArrayList<>();
        List count2 = new ArrayList<>();
        List count3 = new ArrayList<>();

        //用来存放business_type=1的数据
        List<Map> tt1=new ArrayList<>();
        List<Map> tt2=new ArrayList<>();
        List<Map> tt3=new ArrayList<>();

        //循环遍历分别拿出key 和value
        for(Map map:log){
            datax.add(String.valueOf(map.get("oper_time")));
            type.add(Integer.valueOf(map.get("business_type").toString()));
            if(map.get("business_type").equals(1)){
                tt1.add(map);
                for(Map map1:tt1){
                    count1.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
            if(map.get("business_type").equals(2)){
                tt2.add(map);
                for(Map map1:tt2){
                    count2.add(Integer.valueOf(map.get("count").toString()));
                }
            }
            if(map.get("business_type").equals(3)){
                tt3.add(map);
                for(Map map1:tt3){
                    count3.add(Integer.valueOf(map1.get("count").toString()));
                }
            }
        }
        System.out.println(datax);
        //生成一个新的数组xindate用来存储hedate去除重复后的数组
      List newdatax=  new ArrayList();
      for (int i=0;i<datax.size();i++){
          if(!newdatax.contains(datax.get(i))){
              newdatax.add(datax.get(i));
          }
      }
        Map logdata = new HashMap();
        logdata.put("newdatax",newdatax);
        logdata.put("type",type);
        logdata.put("count1",count2);
        logdata.put("count2",count3);
        logdata.put("3",count1);

        return R.ok().put("logdata",logdata);
    }


}
